C	Copyright Eric Fuller, 2001-2007

	SUBROUTINE STATS(NDAT,MFIT,X1,X2,Y1,Y2,Z1,Z2)

	INCLUDE 'pfit.cmn'

	INTEGER*4 NDAT,MFIT
	REAL*8 X1(NMAX),X2(NMAX),Y1(NMAX),Y2(NMAX),Z1(NMAX),Z2(NMAX)



	INTEGER*4 I
	REAL*8 SUM,AVG,SD,TMP,TMQ



	WRITE(*,30)

C	SHOW RAW POINTING STATISTICS
	SUM=0.0

	DO I=1,NDAT
	  SUM=SUM+(Y1(I)-X1(I))
	  ENDDO
	AVG=SUM/NDAT
	SUM=0.0
	DO I=1,NDAT
	  SUM=SUM+((Y1(I)-X1(I))-AVG)**2
	  ENDDO
	SD=SQRT(SUM/(NDAT-1))

	TMP=SD

	SUM=0.0
	DO I=1,NDAT
	  SUM=SUM+(Y2(I)-X2(I))
	  ENDDO
	AVG=SUM/NDAT
	SUM=0.0
	DO I=1,NDAT
	  SUM=SUM+((Y2(I)-X2(I))-AVG)**2
	  ENDDO
	SD=SQRT(SUM/(NDAT-1))

	TMQ=NDAT/(NDAT-MFIT)

	WRITE(*,40) TMP*60.0,SD*60.0,SQRT(TMP**2+SD**2)*60.0*SQRT(TMQ)



C	SHOW FIXED POINTING STATISTICS
	SUM=0.0

	DO I=1,NDAT
	  SUM=SUM+(Y1(I)-Z1(I))
	  ENDDO
	AVG=SUM/NDAT
	SUM=0.0
	DO I=1,NDAT
	  SUM=SUM+((Y1(I)-Z1(I))-AVG)**2
	  ENDDO
	SD=SQRT(SUM/(NDAT-1))

	TMP=SD

	SUM=0.0
	DO I=1,NDAT
	  SUM=SUM+(Y2(I)-Z2(I))
	  ENDDO
	AVG=SUM/NDAT
	SUM=0.0
	DO I=1,NDAT
	  SUM=SUM+((Y2(I)-Z2(I))-AVG)**2
	  ENDDO
	SD=SQRT(SUM/(NDAT-1))

	TMQ=NDAT/(NDAT-MFIT)

	WRITE(*,42) TMP*60,SD*60.0,SQRT(TMP**2+SD**2)*60.0*SQRT(TMQ)


30	FORMAT('                      SD(X)        SD(Y)        PSD')
40	FORMAT('Raw Pointing      : ',F8.3,4X,F8.3,4X,F8.3)

42	FORMAT('Fixed Pointing    : ',F8.3,4X,F8.3,4X,F8.3)



	RETURN

	END


